<?php
App::uses('AppModel', 'Model');
/**
 * Option Model
 *
 */
class Option extends AppModel {

/**
 * Validation rules
 *
 * @var array
 */
	public $validate = array(
		'name' => array(
			'notEmpty' => array(
				'rule' => array('notEmpty'),
				'message' => 'A name is required',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
			'duplicate'	=> array(
				'rule'	=> 'isUnique',
				'message'	=> 'A name already exists',
			),
		),
		'value' => array(
			'notEmpty' => array(
				'rule' => array('notEmpty'),
				'message' => 'A value is required',
				//'allowEmpty' => false,
				//'required' => false,
				//'last' => false, // Stop validation after this rule
				//'on' => 'create', // Limit validation to 'create' or 'update' operations
			),
		),
	);

	public function duplicate($check)
	{
		$check[] = array('id <>' . $this->data[$this->name]['id']);
        $check = $this->find('count', array('conditions'    => $check, 'recursive'  => -1));
        return ($check == 0);
	}
}
